#pragma once

#include <QtGui/QMainWindow>
#include <QtCore/QVector>
#include <QtCore/QMap>
#include <QtCore/QSet>
#include <QtWebKit/QWebPage>
#include <QtCore/QTextStream>

class QAction;
class QToolBar;
class QLineEdit;
class QCheckBox;
class WebBrowser;
class QTabWidget;
class Bookmarks;
class QKeyEvent;
class TextWindow;
class QLabel;

class MainWindow : public QMainWindow
{
	Q_OBJECT
public:
	MainWindow(const QString& windowName, QWidget *parent = 0);
	~MainWindow();
public slots:
	void slot_addressEntered();
	void slot_updateAddress();
	void slot_urlChanged(const QUrl&);
	void slot_linkClicked(const QUrl&);

	void slot_newTab();
	void slot_titleChanged(const QString&);
	void slot_tabCloseRequested(int index);

  void slot_backward();
  void slot_forward();
  void slot_copyText();
  void slot_searchText();

	void slot_saveBookmark();
	void slot_loadBookmark();
	void slot_removeBookmark();
	void slot_bookmark();
	void slot_bookmarkClicked();
	void slot_refreshBookmarkToolbar();

	void slot_translate();
	void slot_translateText();
	void slot_translateFinished();
	void slot_autoTranslateFinished();
	void slot_loadFinished(bool);
	void slot_loadProgress(int);
	void slot_linkHovered(const QString &, const QString &, const QString &);

  void slot_saveTrustedHost();
  void slot_loadTrustedHost();
protected:
	QAction *m_actNewTab, *m_actGo, 
          *m_actBackward, *m_actForward, *m_actCopyText, *m_actSearchText,
          *m_actSaveBookmark, *m_actLoadBookmark, *m_actBookmark, *m_actRemoveBookmark,
		      *m_actTranslate, *m_actTranslateText;
	QVector<QAction*> m_actBookmarkVec;
	QToolBar *m_tbFile, *m_tbAddress, *m_tbBookmark, *m_tbBrowserAction;
	QLineEdit *m_edAddress;
	QCheckBox *m_chkAutoTranslate;
	QTabWidget *m_tab;
	Bookmarks *m_bookmark;
  QLabel *m_lblStatus;
//	QMap<WebBrowser*, WebBrowser*> m_browserMap;
	QSet<QString> m_trustedHost;
  QString m_lastFindText;
  TextWindow *m_textWindow;
  QUrl m_currentUrl;
  QTextStream m_log;
	void createActions();
	void createWidgets();
	void createToolbar();
	void createLayout();
	void connectSignals();

  void keyPressEvent(QKeyEvent *event);

public:
	WebBrowser* currentBrowser();
	WebBrowser* addBrowser(bool original, const QString &url = "google.com");
  void browserAction(QWebPage::WebAction action);
  void addTrustedHost(const QString& host);
  void loadUrl(WebBrowser *s, const QUrl &url);
};
